package com.example.gamestore.control;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.gamestore.Bean.Detail;
import com.example.gamestore.Bean.Game;
import com.example.gamestore.mapper.GameMapper;
import com.example.gamestore.service.DetailService;
import com.example.gamestore.service.GameService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;

@Controller
public class GameTableControl {
    @Autowired
   private GameService gameService;
    @Autowired
    private GameMapper gameMapper;
    @Autowired
    private DetailService detailService;
    @GetMapping("/games")
    public String Games(@RequestParam(value = "pn",defaultValue = "1") Integer pn, Model model){
        PageHelper.startPage(pn,6);
        List<Game> list = gameMapper.selectList(null);
        PageInfo<Game> resultpage=new PageInfo<>(list,5);
        model.addAttribute("pages",resultpage);
        return "games";
    }
    @GetMapping("/gamesdetails")
    public String gamesdetails(@RequestParam(value = "id",defaultValue = "1") Integer gameid,Model model){
        Detail detail=detailService.selectdetailbygameid(gameid);
        Game game=gameService.selectGameByid(gameid);
        model.addAttribute("detail",detail).addAttribute("game",game);
        return "games-details";
    }
}
